const jwt = require('jsonwebtoken')

// 生成Token的函数
function generateToken(user) {
  const payload = {
    userId: user._id,
    username: user.username,
    role: user.role,
  }

  const secretKey = 'your_secret_key'
  const expiresIn = '1h'

  const token = jwt.sign(payload, secretKey, { expiresIn })

  return token
}

module.exports = { generateToken }
